<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.blurry"
          clearable
          placeholder="患者/医生/诊所"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <el-input
          v-model="query.operName"
          clearable
          placeholder="发起人"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        ></el-input>
        <date-range-picker
          v-model="query.createTime"
          start-placeholder="发起开始时间"
          end-placeholder="发起结束时间"
          class="filter-item"
          style="width:auto"
          clearable
          placeholder="发起时间"
          value-format="yyyy-MM-dd 00:00:00"
          @keyup.enter.native="crud.toQuery"
        ></date-range-picker>
        <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
        <crudOperation>
          <el-button
            slot="left"
            :loading="crud.downloadLoading"
            :disabled="!crud.data.length"
            size="mini"
            type="warning"
            icon="el-icon-download"
            @click="doExport"
          >导出</el-button>
          <rrOperation slot="optsLeft" :crud="crud"></rrOperation>
        </crudOperation>
      </div>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        stripe
        :data="crud.data"
        size="small"
        style="width: 100%"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="patientName" sortable label="患者姓名" width="120"></el-table-column>
        <el-table-column prop="patientId" sortable label="患者编号" width="150"></el-table-column>
        <el-table-column prop="sourceClinicName" sortable label="原诊所" width="120"></el-table-column>
        <el-table-column prop="sourceDoctorName" sortable label="原医生" width="120"></el-table-column>
        <el-table-column prop="destClinicName" sortable label="新诊所" width="120"></el-table-column>
        <el-table-column prop="destDoctorName" sortable label="新医生" width="120"></el-table-column>
        <el-table-column prop="operName" sortable label="发起人" width="120"></el-table-column>
        <el-table-column prop="createDate" sortable label="发起时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>
    </div>
  </div>
</template>

<script>
import crudPatient from '@/api/patient';
import { download } from '@/api/data';
import { downloadFile } from '@/utils/index';
import CRUD, { presenter, header, crud } from '@crud/crud';
import rrOperation from '@crud/RR.operation';
import crudOperation from '@crud/CRUD.operation';
import pagination from '@crud/Pagination';
import DateRangePicker from '@/components/DateRangePicker';

export default {
  name: 'Transfer',
  components: {
    pagination,
    crudOperation,
    rrOperation,
    DateRangePicker
  },
  mixins: [presenter(), header(), crud()],
  dicts: [],
  cruds() {
    return CRUD({
      title: '转移患者',
      url: '/patient/patientTransfer/queryPage',
      sort: 'id,desc',
      crudMethod: { ...crudPatient },
      props: { searchToggle: true },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      },
      optRightShow: {
        search: false,
        refresh: false
      }
    });
  },
  data() {
    return {
      permission: {}
    };
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    },
    // 导出
    doExport() {
      this.crud.downloadLoading = true;
      download('/patient/patientTransfer/download', this.crud.getQueryParams())
        .then((result) => {
          downloadFile(result, this.crud.title + '数据', 'xlsx');
          this.crud.downloadLoading = false;
        })
        .catch(() => {
          this.crud.downloadLoading = false;
        });
    }
  }
};
</script>

<style scoped>
.topOperation > .el-button {
  margin-right: 10px;
  margin-bottom: 20px;
}
.filter-item {
  margin-bottom: 5px;
}
</style>
